package com.imti.controller;

import com.imti.bean.DeskInfo;
import com.imti.bean.Doctor;
import com.imti.bean.Duty;
import com.imti.bean.pojo.Dutya;
import com.imti.service.DutyService;
import com.imti.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/duty")
public class DutyController {

    @Autowired
    private DutyService dutyService;

    /*医生值班页面查询*/
    @RequestMapping("/page")
    public String findAllDuty(Dutya dutya, PageBean page, HttpServletRequest request) {
            Map<String,Object> map = new HashMap<String,Object>();
            map.put("dutya", dutya);
            map.put("page", page);
            PageBean p = dutyService.pageDuty(map);
            request.setAttribute("page", p);
        return "duty-list";
    }
    /*添加页面跳转*/
    @RequestMapping("/addDuty")
    public String addNurs(HttpServletRequest request){
        List<Doctor> doctorList = dutyService.fillAllDoctor();
        request.setAttribute("doctorList", doctorList);
        return "duty-add";
    }
    /*分配科室页面跳转*/
    @RequestMapping("/updateDeskWork")
    public String updatedeskwork(Dutya dutya, HttpServletRequest request) {
        HashMap Map = new HashMap();
        Map.put("duty",dutya);
        List<Dutya> duty = dutyService.selectByDutyId(dutya);
        request.setAttribute("duty",duty);
        List<DeskInfo> deskList = dutyService.findAllDesk();
        request.setAttribute("deskList", deskList);
        return "duty-updateDeskwork";
    }
    /*调班页面跳转*/
    @RequestMapping("/updateDuty")
    public String updateduty(Dutya dutya,HttpServletRequest request) {
        HashMap Map = new HashMap();
        Map.put("duty",dutya);
        List<Dutya> duty = dutyService.selectByDutyId(dutya);
        return "duty-update";
    }
    /*添加值班医生数据*/
    @RequestMapping("/saveDuty")
    @ResponseBody
    public String insertduty(Dutya dutya){
        int res = dutyService.insert(dutya);
        return res > 0 ? "1" : "0";
    }

    /*修改科室*/
    @RequestMapping("/saveDeskWork")
    @ResponseBody
    public String updateDuty(Dutya dutya){
        int res = dutyService.updateDuty(dutya);
        return res > 0 ?"1":"0";
    }

    @RequestMapping("/saveDutys")
    @ResponseBody
    public String updateduty(Dutya dutya){
        int res = dutyService.updateDuty(dutya);
        return res > 0 ? "1" : "0";
    }
}
